<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta charset="UTF-8">
    <script src="js/touchDrag.js"></script>
    <title></title>
    <style>
        html,body{margin: 0;padding: 0;width: 100%;height: 100%;}

        .scrollease{transition: all 0.3s cubic-bezier(0,1,1,1);}
        .main{
            width: 100%;
            height: 100%;
            /* 用户自己滚动 */
            overflow: auto;
            -webkit-overflow-scrolling: touch;
        }
        .wrap {
            width: 100%; height: 100%;
            /*弹性盒子*/
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            /*从上向下垂直排列子元素。*/
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
            flex-flow: column;
        }

        .wrap >dl {
            flex:0 0 100%;
            position: relative;
            width: 100%;
            margin: 0;
            overflow: hidden;
            background-color: antiquewhite;
        }

        .text {
            position: absolute;left: 5%;top: 50%;
            font-size: 50px;color: white;line-height: 1.5;
            text-shadow:0 10px 20px rgba(0, 0, 0, 0.4);
        }
        .objcover{width: 100%;height: 100%;object-fit: cover;}
        .objcontain{width: 100%;height: 100%;object-fit: contain;}

        div img{display: block;-webkit-user-drag: none;}
    </style>
</head>

<body>

    <div class="main">
        <div class="wrap">
            <dl>
                <img src="images/tu1.jpg" class="objcover scrollpos" sc="-0.8">
                <div class="text scrollpos" sc="0.7">图片1<br><span style="font-size: 22px">PC端浏览器请模拟触摸屏浏览<br><a href="http://www.flashme.cn" target="_blank">my web</a></span></div>
                <div class="text scrollpos" sc="-0.5" style="left: 30%">跟着走</div>
            </dl>
            <dl>
                <img src="images/tu2.jpg" class="objcontain">
                <div class="text scrollpos" sc="0.7">图片2</div>
                <div class="text scrollpos" sc="-0.5" style="left: 30%">跟着走啊</div>
            </dl>
            <dl>
                <img src="images/tu1.jpg" class="objcover scrollscale" sc="-0.8">
                <div class="text scrollpos" sc="0.5">图片3</div>
            </dl>
            <dl>
                <img src="images/tu2.jpg" class="objcontain">
                <div class="text scrollpos" sc="-0.9">图片4</div>
            </dl>
            <!-- 用户自己滚动，不需要补充高度了 -->
            <!-- <div style="flex:0 0 100%;backdrop-filter: blur(2rem)"></div> -->
        </div>
    </div>


    <script>
        
        const main = document.querySelector('.main');
        const wrap = document.querySelector('.wrap');
        const dl = document.querySelectorAll('.wrap >dl');
        const winH = main.clientHeight;

        dl.forEach((ev, index)=>{
            ev.querySelectorAll('.scrollpos, .scrollscale').forEach((ele, key)=>{
                ele.dataset.index = index;
                ele.dataset.top = ev.offsetTop;
                ele.dataset.offtop = ele.offsetTop;
            })
        })



		main.onscroll = function () {
			scrollPosition(this.scrollTop);
		}

        function scrollPosition(_y) {
            //滚动缩放
            document.querySelectorAll('.scrollscale').forEach(function (ele) {
                var rect = ele.getBoundingClientRect();
                var scale = Math.abs(ele.dataset.top-_y)*0.001 + 1;
                ele.style.transform='scale('+scale+','+scale+')';

            })
            //滚动位移
            document.querySelectorAll('.scrollpos').forEach(function (ele) {
                var sc=Number(ele.getAttribute('sc'));
                ele.style.transform = "translateY(" + ((ele.dataset.top-_y)*sc) + "px)";

            })
        }
    </script>
    
</body>

</html>